package com.anthonybennis.blender.client;

import com.anthonybennis.blender.client.System.SCREEN_WIDTHS;
import com.anthonybennis.blender.client.images.ImageClientBundle;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.widget.button.ImageButton;
import com.googlecode.mgwt.ui.client.widget.header.HeaderPanel;
import com.googlecode.mgwt.ui.client.widget.panel.flex.FlexSpacer;

/**
 * 
 * @author abennis
 */
public class MGWTHeaderPanel extends HeaderPanel
{
	private final Navigatgor _navigator;
	private ImageClientBundle _imageClientBunde;	
	
	/**
	 * 
	 * @param _imageClientBunde
	 */
	public MGWTHeaderPanel(ImageClientBundle imageClientBunde, Navigatgor navigator)
	{
		_imageClientBunde = imageClientBunde;
		_navigator = navigator;
	}
	
	/**
	 * 
	 * @return
	 */
	public void createBlenderCompanionHeader()
	{
		final String ANDROID_BLUE = "#0099CC";
		Util.setBackground(this.container, ANDROID_BLUE);
		
		this.container.setHeight("100%");
		
		/*
		 * Menu Button
		 * (Only needed for Portrait)
		 */
		System.SCREEN_WIDTHS screenWidth = System.getScreenWidth();
		if (screenWidth == SCREEN_WIDTHS.SMALL_WIDTH)
		{
			final ImageResource menuButtonImageResource = _imageClientBunde.headerMenu();
			ImageButton menuButton = new ImageButton(menuButtonImageResource);
			menuButton.setSmall(false);
			menuButton.setWidth("50%");
			menuButton.addTapHandler(new TapHandler() {
				
				@Override
				public void onTap(TapEvent event) {
					Element navigationPanelElement = DOM.getElementById("nav-panel");
					Element parentPanelElement = DOM.getElementById("shortcutspage");
					DockLayoutPanel panel = (DockLayoutPanel)Util.getWidget(parentPanelElement);
					Panel navigationPanel = (Panel) Util.getWidget(navigationPanelElement);
					Double width = panel.getWidgetSize(navigationPanel);
					if (width == 0)
					{
						panel.setWidgetSize(navigationPanel, UIConstants.NAVIGATION_PANEL_WIDTH);
					}
					else
					{
						panel.setWidgetSize(navigationPanel, 0);
					}
					
					panel.animate(500);
				}
			});
			
		
			this.add(menuButton);
			this.add(new FlexSpacer());
		}
		
		
		/*
		 * Blender Companion app icon.
		 */
		ImageResource headerrIconImageResource = _imageClientBunde.headerIcon();
		Image logoImage = new Image(headerrIconImageResource);
		
		this.add(logoImage);
		this.add(new FlexSpacer());
		
		/*
		 * App Name
		 */
		Label headerLabel = new Label("Blender Companion");
		headerLabel.setStyleName("header-label");
		
		SCREEN_WIDTHS width = System.getScreenWidth();
		if (width == SCREEN_WIDTHS.SMALL_WIDTH)
		{
			headerLabel.getElement().getStyle().setFontSize(15, Unit.PT);
		}
		
		this.add(headerLabel);
		this.add(new FlexSpacer());
	}
}